<?php

namespace app\adminapi\lists\room\department;


use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\room\department\RoomDepartment;
use app\common\model\room\department\RoomDepartmentDeviceLog;
use app\common\lists\ListsSearchInterface;


/**
 * 科室设备记录列表
 * Class RoomDepartmentDeviceLogLists
 * @package app\adminapi\listsroom
 */
class RoomDepartmentDeviceLogLists extends BaseAdminDataLists implements ListsSearchInterface
{


    /**
     * @notes 设置搜索条件
     * @return \string[][]
     * @author likeadmin
     * @date 2024/02/23 10:30
     */
    public function setSearch(): array
    {
        return [
            '=' => ['status'],

        ];
    }

    /**
     * @notes 搜索条件
     * @  
     * @date 2023/2/24 16:08
     */
    public function queryWhere()
    {
        $where = [];
        if (!empty($this->params['device'])) {
            if (isset($this->params['device'][0])) {
                $where[] = ['cid', '=', $this->params['building'][0]];
            }
            if (isset($this->params['device'][1])) {
                $where[] = ['bid', '=', $this->params['building'][1]];
            }
            if (isset($this->params['device'][2])) {
                $where[] = ['did', '=', $this->params['building'][2]];
            }
        }
        return $where;
    }

    /**
     * @notes 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author likeadmin
     * @date 2024/02/23 10:30
     */
    public function lists(): array
    {
        return RoomDepartmentDeviceLog::where($this->searchWhere)
            ->field('*')
            ->where($this->queryWhere())
            ->limit($this->limitOffset, $this->limitLength)
            ->order(['id' => 'desc'])
            ->select()
            ->toArray();
    }


    /**
     * @notes 获取数量
     * @return int
     * @author likeadmin
     * @date 2024/02/23 10:30
     */
    public function count(): int
    {
        return RoomDepartmentDeviceLog::where($this->searchWhere)->where($this->queryWhere())
            ->count();
    }
}
